package org.jxkj.bean;

import org.jxkj.utils.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Point {

    static Connection connection = null;
    static ResultSet rs = null;
    static PreparedStatement pstmt = null;

    private String pointName;
    private int pointId;

    public Point() {
    }

    public Point(String pointName, int pointId) {
        this.pointName = pointName;
        this.pointId = pointId;
    }

    public String getPointName() {
        return pointName;
    }

    public void setPointName(String pointName) {
        this.pointName = pointName;
    }

    public int getPointId() {
        return pointId;
    }

    public void setPointId(int pointId) {
        this.pointId = pointId;
    }

    @Override
    public String toString() {
        return "Point{" +
                "pointName='" + pointName + '\'' +
                ", pointId=" + pointId +
                '}';
    }


    // 从数据库获得点名
    public List<Point> getListPoint(int taskId) {

        List<Point> list = new ArrayList();
        try {
            connection = DruidUtils.newInstance().getConnection();
            String sql = "select * from hms_cm_point where point_code like 'HMS_%'";
            pstmt = connection.prepareStatement(sql);
            //pstmt.setObject(1, taskId);
            rs = pstmt.executeQuery();
            while(rs.next()){
                String pointName = rs.getString("point_code");
                int pointId = rs.getInt("point_hid");
                list.add(new Point(pointName,pointId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 获取测点的计算标识
     * @param pointCode
     * @return
     */
    public static String getCalcFlag(String pointCode) {
        String calcFlag = null;
        try {
            connection = DruidUtils.newInstance().getConnection();
            String sql = "select calc_flag from hms_cm_point where point_code = ?";
            pstmt = connection.prepareStatement(sql);
            pstmt.setString(1, pointCode);
            rs = pstmt.executeQuery();

            while(rs.next()){
                calcFlag = rs.getString("calc_flag");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return calcFlag;
    }
}
